if (document.getElementById('hold_meeting')){
    var xhr1 = new XMLHttpRequest();
    var local_host1 = window.location.host;          // 获取当前IP
    xhr1.open('post', "/system-setup/MeetingPermissions");
    xhr1.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr1.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr1.send();
    xhr1.onreadystatechange = function () {
        if (xhr1.readyState === 4) {
            if (xhr1.status === 200) {
                var JsonDate = JSON.parse(xhr1.responseText);
                if (JsonDate['meet_flag'] === 'true'){
                    document.getElementById('hold_meeting').style.display='block';
                    document.getElementById('left_ul').style.marginTop='10px;'
                }else {
                    document.getElementById('hold_meeting').style.display='none'
                }
            }
        }
     };
}

function admin_add(title,url,w,h){
    layer_show(title,url,w,h);
}

getNowFormatDate();

var xhr = new XMLHttpRequest();
var local_host = window.location.host;          // 获取当前IP
xhr.open('post', "/system-setup/get_heard_pic", true);
xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.send();
xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
        if (xhr.status === 200) {
            document.getElementById("loading").style.display = "none";
            var JsonDate = JSON.parse(xhr.responseText);
            document.getElementById("model-img").src = JsonDate["head_portrait"];
            if (JsonDate["read_aa"]){
                document.getElementById('msg_warn').style.display="inline-block";
            }
            if (JsonDate["notic_flag"]){
                document.getElementById('notic_warn').style.display="inline-block";
            }
            if (JsonDate["one_count"] !== 0 || JsonDate["two_count"] !== 0) {
                document.getElementById('matters').style.display="inline-block";
                if (document.getElementById('attendance_number')) {
                    if (JsonDate["approve_one"] === "true") {
                        document.getElementById('attendance_number').style.display="inline-block";
                        document.getElementById('attendance_number').innerText=JsonDate["one_count"];
                    }
                    if (JsonDate["approve_two"] === "true") {
                        document.getElementById('statistics_number').style.display="inline-block";
                        document.getElementById('statistics_number').innerText=JsonDate["two_count"];
                    }
                }
            }

            document.getElementById("MorningWorkTime").innerText=JsonDate["clock_dic"]["morning_start"]+" - "+JsonDate["clock_dic"]["morning_end"];
            document.getElementById("AfternoonWorkTime").innerText=JsonDate["clock_dic"]["afternoon_start"]+" - "+JsonDate["clock_dic"]["afternoon_end"];
            document.getElementById("morning_start").innerText=JsonDate["clock_dic"]["check_in_one_time"];
            document.getElementById("morning_end").innerText=JsonDate["clock_dic"]["check_in_two_time"];
            document.getElementById("afternoon_start").innerText=JsonDate["clock_dic"]["check_in_three_time"];
            document.getElementById("afternoon_end").innerText=JsonDate["clock_dic"]["check_in_four_time"];
        }
    }
 };

shenpi_model();
function shenpi_model() {
    if (!document.getElementById("Tip_number")){
        return false
    }
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('get', "/administrative/get_backlog_view");
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                if (JsonDate["num"]){
                    document.getElementById("Tip_number").innerText=JsonDate["num"];
                    document.getElementById("Tip_number").style.display="table-row";
                }
                if (JsonDate["num1"]){
                    if (parseInt(JsonDate["num1"]) >= 100){
                        document.getElementById("Received_number").innerText='99+'
                    }else {
                        document.getElementById("Received_number").innerText=JsonDate["num1"];
                    }
                    document.getElementById("Received_number").style.display="table-row";
                }
                if (JsonDate["make_count"]){
                    document.getElementById("process").innerText=JsonDate["make_count"];
                    document.getElementById("process").style.display="table-row";
                }
                if (JsonDate["number2"]) {
                    document.getElementById("sup_number").innerText=JsonDate["number2"];
                    document.getElementById("sup_number").style.display="table-row";
                }
            }
        }
    };
}

function permissions_validation(a_href, permissions_type) {
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/system-setup/permissions_validation");
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.send("permissions_type="+permissions_type);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                var permissions_flag = false;

                for(var key in JsonDate["permissions"]){
                    if (JsonDate["permissions"][key]){
                        permissions_flag = true;
                        break
                    }
                }
                if (permissions_flag){
                    window.location.href=a_href;
                }
                if (!permissions_flag){
                    alert("您的访问权限不足！")
                }
            }
        }
    };
}

// var chat_frame = document.getElementById('chat-frame');
//  //onmousedown   当鼠标按住chat_frame之后，可以拖动元素
//  chat_frame.ondragstart = function(){
//      var disX = event.clientX - this.offsetLeft;
//      var disY = event.clientY - this.offsetTop;
//      // 复制一个跟chat_frame一样的div
//      var clone = this.cloneNode();
//      clone.removeAttribute('id');
//      clone.style.opacity = 0.3;
//      document.body.appendChild(clone);
//
//      document.onmousemove = function(){
//          clone.style.left = event.clientX - disX + "px";
//          clone.style.top = event.clientY - disY + "px";
//      }
//      document.onmouseup = function(){
//          document.onmousemove = null;
//          chat_frame.style.left = clone.style.left;
//          chat_frame.style.top = clone.style.top;
//          document.body.removeChild(clone);
//      }
//  }

var body = document.body;
var div = document.getElementById("work_card");
var btnShow = document.getElementById("display_kaoqin");

//点击body，div消失
body.addEventListener('click', function() {
    div.style.display = 'none';
})

//点击div，阻止body的div消失的事件
div.addEventListener('click', function(e) {
    e.stopPropagation();
})

//点击出现按钮，阻止body的div消失事件，且令div出现
btnShow.addEventListener('click', function(e) {
    e.stopPropagation();
    div.style.display = 'block';
})

function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    document.getElementById("now_date").innerText=currentdate;
    var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    var now = new Date();
    var day = now.getDay();
    var week_day = weeks[day];
    document.getElementById("now_week").innerText=week_day;
}


function system_integration() {
    document.getElementById('system_integration').style.display = 'inline-block';
}

function xiaoshi_page() {
    document.getElementById('system_integration').style.display = 'none';
}